import java.util.Scanner;

public class JianghuGame {
    private static int health = 100;
    private static int money = 0;
    private static int reputation = 0;
    private static int level = 1;
    private static int experience = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎来到江湖游戏！");
        System.out.println("你的初始属性为：");
        printStatus();

        while (true) {
            System.out.println("请选择你要进行的操作：");
            System.out.println("1. 打怪升级");
            System.out.println("2. 做任务赚钱");
            System.out.println("3. 做生意赚钱");
            System.out.println("4. 查看属性");
            System.out.println("5. 退出游戏");

            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    fight();
                    break;
                case 2:
                    doTask();
                    break;
                case 3:
                    doBusiness();
                    break;
                case 4:
                    printStatus();
                    break;
                case 5:
                    System.out.println("谢谢游玩！");
                    return;
                default:
                    System.out.println("无效的选择，请重新输入。");
                    break;
            }
        }
    }

    private static void printStatus() {
        System.out.println("等级：" + level);
        System.out.println("经验值：" + experience);
        System.out.println("生命值：" + health);
        System.out.println("金钱：" + money);
        System.out.println("声望：" + reputation);
    }

    private static void fight() {
        System.out.println("你遇到了一只恶魔！");
        int enemyHealth = 50;
        while (enemyHealth > 0 && health > 0) {
            System.out.println("你的生命值：" + health);
            System.out.println("恶魔的生命值：" + enemyHealth);
            System.out.println("请选择你要使用的技能：");
            System.out.println("1. 普通攻击");
            System.out.println("2. 火球术");
            System.out.println("3. 治疗术");

            Scanner scanner = new Scanner(System.in);
            int skill = scanner.nextInt();
            switch (skill) {
                case 1:
                    System.out.println("你使用了普通攻击，对恶魔造成了10点伤害。");
                    enemyHealth -= 10;
                    break;
                case 2:
                    System.out.println("你使用了火球术，对恶魔造成了20点伤害。");
                    enemyHealth -= 20;
                    break;
                case 3:
                    System.out.println("你使用了治疗术，恢复了10点生命值。");
                    health += 10;
                    break;
                default:
                    System.out.println("无效的选择，请重新输入。");
                    break;
            }

            if (enemyHealth > 0) {
                System.out.println("恶魔使用了普通攻击，对你造成了10点伤害。");
                health -= 10;
            }
        }

        if (health > 0) {
            System.out.println("你打败了恶魔，获得了50点经验值和10金钱。");
            experience += 50;
            money += 10;
            if (experience >= level * 100) {
                levelUp();
            }
        } else {
            System.out.println("你被恶魔打败了，游戏结束。");
            System.exit(0);
        }
    }

    private static void doTask() {
        System.out.println("你接到了一个任务：护送商队到下一个城镇。");
        System.out.println("你需要在规定时间内完成任务，否则任务失败。");
        int time = 5;
        int distance = 100;
        while (time > 0 && distance > 0) {
            System.out.println("距离目的地还有" + distance + "公里，剩余时间" + time + "天。");
            System.out.println("请选择你要进行的操作：");
            System.out.println("1. 继续前进");
            System.out.println("2. 休息一天");
            System.out.println("3. 放弃任务");

            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("你继续前进，消耗了一天时间。");
                    distance -= 20;
                    time--;
                    break;
                case 2:
                    System.out.println("你休息了一天，恢复了10点生命值。");
                    health += 10;
                    time--;
                    break;
                case 3:
                    System.out.println("你放弃了任务，获得了10金钱。");
                    money += 10;
                    return;
                default:
                    System.out.println("无效的选择，请重新输入。");
                    break;
            }
        }

        if (distance <= 0) {
            System.out.println("你成功护送商队到达下一个城镇，获得了50金钱和50声望。");
            money += 50;
            reputation += 50;
        } else {
            System.out.println("你没有在规定时间内完成任务，任务失败。");
        }
    }

    private static void doBusiness() {
        System.out.println("你来到了一个城镇，想要做点生意。");
        System.out.println("请选择你要进行的生意：");
        System.out.println("1. 买入物品");
        System.out.println("2. 卖出物品");
        System.out.println("3. 离开城镇");

        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                System.out.println("你买入了10个草药，花费了20金钱。");
                money -= 20;
                break;
            case 2:
                System.out.println("你卖出了10个草药，获得了30金钱。");
                money += 30;
                break;
            case 3:
                System.out.println("你离开了城镇。");
                break;
            default:
                System.out.println("无效的选择，请重新输入。");
                break;
        }
    }

    private static void levelUp() {
        System.out.println("你升级了，等级提升到" + (level + 1) + "级！");
        level++;
        experience -= level * 100;
        health += 20;
        money += 50;
        reputation += 20;
    }
}